package com.sunb2b.service;

import java.util.List;

import javax.inject.Inject;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Service;

import com.sunb2b.dao.*;
import com.sunb2b.entity.*;
import com.sunb2b.pojo.PageSearchResult;

@Service
public class ProductService {
	@Inject
	private ProductDAO productDAO;
	@Inject
	private ProductDetailDAO pdDAO;
	
	
	public void save(Product p){
		productDAO.save(p);
	}
	
	public Product getProduct(int id){
		return productDAO.findById(id);
	}
	
	public void deleteProduct(Product p){
		// mark it as inactive;
		// not implemented yet.
		//Product p = productDAO.findById(id);
		//p.setStatus("INAC");
		//productDAO.save(p);
		productDAO.delete(p);
	}
    public List getProductDetailsByProduct(Product p){
        return pdDAO.findByProduct(p);
    }
    
    public List listAll(){
    	return productDAO.findAll();
    }
    
    public PageSearchResult search(DetachedCriteria dc, int page, int pageSize){
    	return productDAO.search(dc, page, pageSize);
    }

}
